import { FlowNodeTemplateTypeEnum, FlowNodeTypeEnum } from '../constant';
import { FlowNodeTemplateType, NodeTemplateListItemType } from '../node';

import { DatabaseConnectionModule } from './plugin/databaseConnection';
import { DindTalkRobotModule } from './plugin/dingding';
import { FeishuRobotModule } from './plugin/feishuRobot';
import { FetchUrlModule } from './plugin/fetchUrl';
import { GetTimeModule } from './plugin/getTime';
import { SmtpModule } from './plugin/smtp';
import { WechatWorkRobotModule } from './plugin/wechatWork';
import { RunAppModule } from './system/abandoned/runApp/index';
import { AiChatModule } from './system/aiChat';
import { AssignedAnswerModule } from './system/assignedAnswer';
import { ClassifyQuestionModule } from './system/classifyQuestion/index';
import { ContextExtractModule } from './system/contextExtract/index';
import { DatasetConcatModule } from './system/datasetConcat';
import { DatasetSearchModule } from './system/datasetSearch';
import { EmptyNode } from './system/emptyNode';
import { HttpNode468 } from './system/http468';
import { IfElseNode } from './system/ifElse/index';
import { FormInputNode } from './system/interactive/formInput';
import { UserSelectNode } from './system/interactive/userSelect';
import { LoopNode } from './system/loop/loop';
import { LoopEndNode } from './system/loop/loopEnd';
import { LoopStartNode } from './system/loop/loopStart';
import { PluginConfigNode } from './system/pluginConfig';
import { PluginInputModule } from './system/pluginInput';
import { PluginOutputModule } from './system/pluginOutput';
import { AiQueryExtension } from './system/queryExtension';
import { RunAppNode } from './system/runApp';
import { RunPluginModule } from './system/runPlugin';
import { CodeNode } from './system/sandbox';
import { TextEditorNode } from './system/textEditor';
import { ToolModule } from './system/tools';
import { VariableUpdateNode } from './system/variableUpdate';
import { WorkflowStart } from './system/workflowStart';

const systemNodes: FlowNodeTemplateType[] = [
  AiChatModule,
  TextEditorNode,
  AssignedAnswerModule,
  DatasetSearchModule,
  ClassifyQuestionModule,
  ContextExtractModule,
  DatasetConcatModule,
  ToolModule,
  // ToolParamsNode,
  // StopToolNode,
  // ReadFilesNode,
  HttpNode468,
  AiQueryExtension,
  // LafModule,
  IfElseNode,
  VariableUpdateNode,
  CodeNode,
  LoopNode,
];
/* app flow module templates */
export const appSystemModuleTemplates: FlowNodeTemplateType[] = [
  // SystemConfigNode,
  WorkflowStart,
  ...systemNodes,
  // CustomFeedbackNode,
  UserSelectNode,
  FormInputNode,
];
/* plugin flow module templates */
export const pluginSystemModuleTemplates: FlowNodeTemplateType[] = [
  PluginConfigNode,
  PluginInputModule,
  PluginOutputModule,
  ...systemNodes,
];

export const localPluginTemples = [
  GetTimeModule,
  FeishuRobotModule,
  FetchUrlModule,
  DatabaseConnectionModule,
  DindTalkRobotModule,
  WechatWorkRobotModule,
  SmtpModule,
];

export const localPluginModules: NodeTemplateListItemType[] = [
  {
    id: 'community-getTime',
    parentId: null,
    templateType: FlowNodeTemplateTypeEnum.tools,
    flowNodeType: FlowNodeTypeEnum.pluginModule,
    avatar: 'core/workflow/template/getTime',
    name: '时间',
    intro: '一个用于获取当前时间的插件。',
    isTool: true,
    author: '',
  },
  {
    id: 'community-fetchUrl',
    parentId: null,
    templateType: FlowNodeTemplateTypeEnum.tools,
    flowNodeType: FlowNodeTypeEnum.pluginModule,
    avatar: 'core/workflow/template/fetchUrl',
    name: '网页抓取',
    intro: '一个用于抓取网页的插件，仅支持获取静态网站，返回的数据格式为 Markdown。',
    isTool: true,
    author: '',
  },
  {
    id: 'community-feishu',
    parentId: null,
    templateType: FlowNodeTemplateTypeEnum.communication,
    flowNodeType: FlowNodeTypeEnum.pluginModule,
    avatar: '/appMarketTemplates/plugin-feishu/avatar.svg',
    name: '飞书机器人',
    intro: '一个用于向飞书机器人发起 webhook 请求的插件。',
    isTool: true,
    author: '',
  },
  {
    id: 'community-databaseConnection',
    parentId: null,
    templateType: FlowNodeTemplateTypeEnum.tools,
    flowNodeType: FlowNodeTypeEnum.pluginModule,
    avatar: 'core/workflow/template/datasource',
    name: '数据库连接',
    intro: '一个用于连接常用数据库，并执行sql的插件。',
    isTool: true,
    author: '',
  },
  {
    id: 'community-dingding',
    parentId: null,
    templateType: FlowNodeTemplateTypeEnum.communication,
    flowNodeType: FlowNodeTypeEnum.pluginModule,
    avatar: 'dingding',
    name: '钉钉机器人',
    intro: '一个用于向钉钉器人发起 webhook 请求的插件。',
    isTool: true,
    author: '',
  },
  {
    id: 'community-wechatWork',
    parentId: null,
    templateType: FlowNodeTemplateTypeEnum.communication,
    flowNodeType: FlowNodeTypeEnum.pluginModule,
    avatar: 'wechatWork',
    name: '企业微信机器人',
    intro: '一个用于向企业微信机器人发起 webhook 请求的插件。',
    isTool: true,
    author: '',
  },
  {
    id: 'community-smtp',
    parentId: null,
    templateType: FlowNodeTemplateTypeEnum.communication,
    flowNodeType: FlowNodeTypeEnum.pluginModule,
    avatar: 'smtp',
    name: '邮件发送',
    intro: '通过SMTP发送电子邮件。',
    isTool: true,
    author: '',
  },
];

/* all module */
export const moduleTemplatesFlat: FlowNodeTemplateType[] = [
  ...appSystemModuleTemplates.concat(
    pluginSystemModuleTemplates.filter(
      (item) => !appSystemModuleTemplates.find((app) => app.id === item.id),
    ),
  ),
  EmptyNode,
  RunPluginModule,
  RunAppNode,
  RunAppModule,
  LoopStartNode,
  LoopEndNode,
  ...localPluginTemples,
];
